package cn.hh;

import cn.hh.wechatkit.HelperLoader;
import cn.hh.wechatkit.component.WxCom_Card;
import cn.hh.wechatkit.component.WxCom_Message;
import cn.hh.wechatkit.component.WxCom_Token;
import cn.hh.wechatkit.component.WxCom_User;
import cn.hh.wechatkit.handler.WxTemplate;
import cn.hh.wechatkit.helper.PropertiesConfigHelper;
import cn.hh.wechatkit.param.WxParam;

public class WxKit {

    static{
    }

    //获取单例
    public static WxKit $wx(){
        return kitHolder.wxKit;
    }

    //单例初始化
    private WxKit() {
        loadBaseClass();
    }

//    加载基础工具
    private void loadBaseClass(){
        HelperLoader.init();
    }

//    通过Properties配置
    public void propertiesInit(String wechatConfigPath) {
        PropertiesConfigHelper.config(wechatConfigPath);
    }


    public String appId(){
        return WxParam.appId;
    }

    public WxKit appId(String appId){
        WxParam.appId=appId;
        return this;
    }

    public String miniAppId(){
        return WxParam.miniAppId;
    }

    public WxKit miniAppId(String miniAppId){
        WxParam.miniAppId=miniAppId;
        return this;
    }

    public String checkToken() {
        return WxParam.checkToken;
    }

    public WxKit checkToken(String checkToken){
        WxParam.checkToken=checkToken;
        return this;
    }

    public String authoRecallUrl() {
        return WxParam.authoRecallUrl;
    }

    public WxKit authoRecallUrl(String authoRecallUrl){
        WxParam.authoRecallUrl=authoRecallUrl;
        return this;
    }

    public String version() {
        return WxParam.version;
    }

    public WxKit version(String version){
        WxParam.version=version;
        return this;
    }

    public String appSecret() {
        return WxParam.appSecret;
    }

    public WxKit appSecret(String appSecret){
        WxParam.appSecret=appSecret;
        return this;
    }

    public String miniAppSecret() {
        return WxParam.miniAppSecret;
    }

    public WxKit miniAppSecret(String miniAppSecret){
        WxParam.miniAppSecret=miniAppSecret;
        return this;
    }

    public long expireTimeAhead() {
        return WxParam.expireTimeAhead;
    }

    public WxKit expireTimeAhead(long expireTimeAhead){
        WxParam.expireTimeAhead=expireTimeAhead;
        return this;
    }

    /**
     * 获取组件
     */

    public WxCom_Card wxCom_card(){
        return wxCom_card;
    }

    public WxCom_Message wxCom_message() {
        return wxCom_message;
    }

    public WxCom_Token wxCom_token(){
        return wxCom_token;
    }

    public WxCom_User wxCom_user(){
        return wxCom_user;
    }

    /**
     * 局部变量
     */
    private WxCom_Card wxCom_card = new WxCom_Card();
    private WxCom_Token wxCom_token = new WxCom_Token();
    private WxCom_User wxCom_user = new WxCom_User();
    private WxCom_Message wxCom_message = new WxCom_Message();

    //单例持有
    private static class kitHolder{
        static WxKit wxKit = new WxKit();
    }

    public WxTemplate getWxTemplate(){
        return new WxTemplate();
    }

}
